
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Text;
 using System.Windows.Forms;
using System.Resources;
using System.Globalization;
namespace LPV_POS.mh_pos.mh_cauhinh
{
    public partial class frmDM_MAYIN_BEP_CAUHINH : Form
    {
        CultureInfo culture;
        //public string ma = "";//PK_: giá trị này dc truyền từ bảng danh sách, trường hợp EDIT
        DataTable tbMain = new DataTable();

        #region "Muti language"

        private void SetLanguage_banhang(string cultureName)
        {
            try
            {
                culture = CultureInfo.CreateSpecificCulture(cultureName);
                ResourceManager rm = new ResourceManager("LPV_POS.Muti_language.MyResource", typeof(frmDM_MAYIN_BEP_CAUHINH).Assembly);
                lblCANH_DUOI.Text = rm.GetString("canhduoi", culture);
                lblCANH_TREN.Text = rm.GetString("canhtren", culture);
                lblCHON_MAYIN.Text = rm.GetString("chonmayinkhiin", culture);
                lblIN_BOPHAN.Text = rm.GetString("inbophan", culture);
                lblIN_GIA.Text = rm.GetString("ingia", culture);
                lblIN_MOIMON_MOTPHIEU.Text = rm.GetString("inmoimonmotphieu", culture);
                lblIN_MON_THEONHOM.Text = rm.GetString("inmontheonhom", culture);
                lblIN_POSNAME.Text = rm.GetString("intenpos", culture);
                lblIN_SO_HOADON.Text = rm.GetString("insohoadon", culture);
                lblIN_TEN_BAN.Text = rm.GetString("intenban", culture);
                chkIN_TEN_HANGHOA.Text = rm.GetString("intenhanghoa", culture);
                chkIN_TEN_HANGHOA_ALIAS.Text = rm.GetString("intenhanghoanick", culture);
                btnLuu.Text = rm.GetString("luu", culture);
                btnDSthoat.Text = rm.GetString("thoat", culture);
                lbel_tencongty.Text = rm.GetString("cauhinhbep", culture);
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Note");
            }

        }

        #endregion
        #region"    frmDM_MAYIN_BEP_CAUHINH"
        public frmDM_MAYIN_BEP_CAUHINH()
        {
            InitializeComponent();
            culture = CultureInfo.CurrentCulture;
        }
        #endregion

        #region"    frmDM_MAYIN_BEP_CAUHINH_Load"
        public void frmDM_MAYIN_BEP_CAUHINH_Load(object sender, EventArgs e)
        {
            cpublic ocpublic = new cpublic();
            string str_lang = ocpublic.Registry_Get("mh_main_lang");
            if (str_lang == "")
                str_lang = "vi-VN";
            SetLanguage_banhang(str_lang);
            this.showinfo(); 
   
        }
        #endregion

        #region"    các hàm load dữ liệu"
        #region"    showdata"
        void showdata()
        {

            thuvien oclsData = new thuvien();//lớp truy xuat du lieu 
            tbMain = oclsData.SP_SelectDataTable("sp_DM_MAYIN_BEP_CAUHINH",
                                                   new string[] { "@flag" },//, "@OBJID" 
                                                   new object[] { 4 });//, ma 

        }
        #endregion
        
        #region"    showinfo"
        void showinfo()
        {
            
            this.showdata();
            if (tbMain.Rows.Count == 0)
            {
                numCANH_DUOI.Value = 0;
                numCANH_TREN.Value = 0;
                chkCHON_MAYIN.Checked = false;
                chkIN_BOPHAN.Checked = false;
                chkIN_GIA.Checked = false;
                chkIN_MOIMON_MOTPHIEU.Checked = false;
                chkIN_MON_THEONHOM.Checked = false;
                chkIN_POSNAME.Checked = false;
                chkIN_SO_HOADON.Checked = false;
                chkIN_TEN_BAN.Checked = false;
                chkIN_TEN_HANGHOA.Checked = false;
                chkIN_TEN_HANGHOA_ALIAS.Checked = false;
                return;
            }
            numCANH_DUOI.Value = decimal.Parse(string.Concat("0" + tbMain.Rows[0]["CANH_DUOI"]).Replace("0-", "-"));
            numCANH_TREN.Value = decimal.Parse(string.Concat("0" + tbMain.Rows[0]["CANH_TREN"]).Replace("0-", "-"));
            chkCHON_MAYIN.Checked = Boolean.Parse("" + tbMain.Rows[0]["CHON_MAYIN"] + "");
            chkIN_BOPHAN.Checked = Boolean.Parse("" + tbMain.Rows[0]["IN_BOPHAN"] + "");
            chkIN_GIA.Checked = Boolean.Parse("" + tbMain.Rows[0]["IN_GIA"] + "");
            chkIN_MOIMON_MOTPHIEU.Checked = Boolean.Parse("" + tbMain.Rows[0]["IN_MOIMON_MOTPHIEU"] + "");
            chkIN_MON_THEONHOM.Checked = Boolean.Parse("" + tbMain.Rows[0]["IN_MON_THEONHOM"] + "");
            chkIN_POSNAME.Checked = Boolean.Parse("" + tbMain.Rows[0]["IN_POSNAME"] + "");
            chkIN_SO_HOADON.Checked = Boolean.Parse("" + tbMain.Rows[0]["IN_SO_HOADON"] + "");
            chkIN_TEN_BAN.Checked = Boolean.Parse("" + tbMain.Rows[0]["IN_TEN_BAN"] + "");
            chkIN_TEN_HANGHOA.Checked = Boolean.Parse("" + tbMain.Rows[0]["IN_TEN_HANGHOA"] + "");
            chkIN_TEN_HANGHOA_ALIAS.Checked = Boolean.Parse("" + tbMain.Rows[0]["IN_TEN_HANGHOA_ALIAS"] + "");

        }
        #endregion

        
        #endregion

        #region"    các sự kiện _Click của các nút THÊM - SỬA- TÌM KIẾM - THOÁT - tbpDanhSach"
        
        #region"    btnDSthoat_Click"
        private void btnDSthoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
        #endregion
        
        #endregion

        #region"    các sự kiện _Click của các nút LƯU - XÓA - SỬA  "
       
        #region"    btnLuu_Click"
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (this.save() >= 0)
            {
                LPV_POS.Module.MessageBox_LPV.Show("Lưu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        #endregion
        #region"    save"
        int save()
        {
            int _iReasult = -1;


            thuvien oclsData = new thuvien();//lớp truy xuat du lieu
            _iReasult = oclsData.SP_Update("sp_DM_MAYIN_BEP_CAUHINH",
                             new string[] { "@flag", "@CANH_DUOI", "@CANH_TREN", "@CHON_MAYIN", "@IN_BOPHAN", "@IN_GIA", "@IN_MOIMON_MOTPHIEU", "@IN_MON_THEONHOM", "@IN_POSNAME", "@IN_SO_HOADON", "@IN_TEN_BAN", "@IN_TEN_HANGHOA", "@IN_TEN_HANGHOA_ALIAS" },
                             new object[] { 1, numCANH_DUOI.Value, numCANH_TREN.Value, chkCHON_MAYIN.Checked, chkIN_BOPHAN.Checked, chkIN_GIA.Checked, chkIN_MOIMON_MOTPHIEU.Checked, chkIN_MON_THEONHOM.Checked, chkIN_POSNAME.Checked, chkIN_SO_HOADON.Checked, chkIN_TEN_BAN.Checked, chkIN_TEN_HANGHOA.Checked, chkIN_TEN_HANGHOA_ALIAS.Checked });

            return _iReasult;
        }
        #endregion

        
        #endregion

        private void numCANH_DUOI_ValueChanged(object sender, EventArgs e)
        {

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {//canh tren
            mh_so omh_chu = new mh_so();
            omh_chu.eClick += new EventHandler(canh_tren);
            omh_chu.ShowDialog();
        }
        private void bton_dautrang_Click(object sender, EventArgs e)
        {
            //canh duoi
            mh_so omh_chu = new mh_so();
            omh_chu.eClick += new EventHandler(canh_duoi);
            omh_chu.ShowDialog();
        }
        void canh_duoi(object sender, EventArgs e)
        {
            try
            {
                mh_so omh_so = (mh_so)sender;
                string s = omh_so.txt_ketqua.Text;
                decimal dvalue = 0;
                decimal.TryParse(s, out dvalue);
                numCANH_DUOI.Value = dvalue;
            }
            catch (Exception ex)
            {

            }
        }

        void canh_tren(object sender, EventArgs e)
        {
            try
            {
                mh_so omh_so = (mh_so)sender;
                string s = omh_so.txt_ketqua.Text;
                decimal dvalue = 0;
                decimal.TryParse(s, out dvalue);
                numCANH_TREN.Value = dvalue;
            }
            catch (Exception ex)
            {

            }
        }
             
        private void chkIN_TEN_HANGHOA_CheckedChanged(object sender, EventArgs e)
        {
            if (chkIN_TEN_HANGHOA.Checked)
                chkIN_TEN_HANGHOA_ALIAS.Checked = false;
        }

        private void chkIN_TEN_HANGHOA_ALIAS_CheckedChanged(object sender, EventArgs e)
        {
            if (chkIN_TEN_HANGHOA_ALIAS.Checked)
                chkIN_TEN_HANGHOA.Checked = false;
        }

    }

}